/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * plcPanel.java
 *
 * Created on Jul 1, 2009, 2:46:46 PM
 */

package coda.gui;

import org.bff.javampd.MPD;
import org.bff.javampd.MPDPlayer;
import org.bff.javampd.MPDPlaylist;

/**
 *
 * @author pan
 */
public class PLCPanel extends javax.swing.JPanel {

    private MPD mpd;

    /** Creates new form plcPanel */
    public PLCPanel(MPD mpd) {
        initComponents();
        //
        this.mpd= mpd;
        //
        update();
    }

    private void update() {
        MPDPlayer player = mpd.getMPDPlayer();
        try {
            continuousButton.setSelected(player.isRepeat());
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        upButton = new javax.swing.JButton();
        upButton1 = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        shuffleButton = new javax.swing.JToggleButton();
        continuousButton = new javax.swing.JToggleButton();

        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });
        setLayout(new java.awt.GridBagLayout());

        upButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/go-up.png"))); // NOI18N
        upButton.setFocusPainted(false);
        upButton.setMaximumSize(new java.awt.Dimension(28, 28));
        upButton.setMinimumSize(new java.awt.Dimension(28, 28));
        upButton.setPreferredSize(new java.awt.Dimension(28, 28));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(4, 2, 2, 2);
        add(upButton, gridBagConstraints);

        upButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/go-down.png"))); // NOI18N
        upButton1.setFocusPainted(false);
        upButton1.setMaximumSize(new java.awt.Dimension(28, 28));
        upButton1.setMinimumSize(new java.awt.Dimension(28, 28));
        upButton1.setPreferredSize(new java.awt.Dimension(28, 28));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(upButton1, gridBagConstraints);

        deleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/delete.png"))); // NOI18N
        deleteButton.setFocusPainted(false);
        deleteButton.setMaximumSize(new java.awt.Dimension(28, 28));
        deleteButton.setMinimumSize(new java.awt.Dimension(28, 28));
        deleteButton.setPreferredSize(new java.awt.Dimension(28, 28));
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(deleteButton, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(4, 2, 4, 2);
        add(jSeparator1, gridBagConstraints);

        shuffleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/shuffle.png"))); // NOI18N
        shuffleButton.setFocusPainted(false);
        shuffleButton.setMaximumSize(new java.awt.Dimension(28, 28));
        shuffleButton.setMinimumSize(new java.awt.Dimension(28, 28));
        shuffleButton.setPreferredSize(new java.awt.Dimension(28, 28));
        shuffleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                shuffleButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(shuffleButton, gridBagConstraints);

        continuousButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/continue.png"))); // NOI18N
        continuousButton.setFocusPainted(false);
        continuousButton.setMaximumSize(new java.awt.Dimension(28, 28));
        continuousButton.setMinimumSize(new java.awt.Dimension(28, 28));
        continuousButton.setPreferredSize(new java.awt.Dimension(28, 28));
        continuousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                continuousButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
        add(continuousButton, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        MainForm.deleteSelectedSongs();
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void shuffleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shuffleButtonActionPerformed
        shuffleButton.setSelected(false); // replace with ordinary jbutton
        MPDPlaylist playlist = mpd.getMPDPlaylist();
        try {
            playlist.shuffle();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }//GEN-LAST:event_shuffleButtonActionPerformed

    private void continuousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_continuousButtonActionPerformed
        MPDPlayer player = mpd.getMPDPlayer();
        try {
            player.setRepeat(continuousButton.isSelected());
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }//GEN-LAST:event_continuousButtonActionPerformed

    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        update();
    }//GEN-LAST:event_formComponentShown


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton continuousButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JToggleButton shuffleButton;
    private javax.swing.JButton upButton;
    private javax.swing.JButton upButton1;
    // End of variables declaration//GEN-END:variables

}
